﻿/*-------------------------------------------------------------------------
* 命名空间: XrayDirection.ValueConverters/DoubleToEmptyStringConverter
* 类       名: DoubleToEmptyStringConverter
* 功      能:  TD
* 时      间:  2024/2/24 11:22:52
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using System;
using System.Globalization;
using System.Windows.Data;

namespace XrayDirection.ValueConverters
{
    public class DoubleToEmptyStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((value is double doubleValue && doubleValue == 0) || value == null)
            {
                return string.Empty;
            }
            return value.ToString()!;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((value is string valueVal && (valueVal == string.Empty || valueVal == "0")))
            {
                return 0;
            }
            else
            {
                return value;
            }
        }
    }
}
